package com.igeekhome.controller;
import com.igeekhome.controller.api.BaseDictControllerApi;
import com.igeekhome.pojo.BaseDict;
import com.igeekhome.pojo.DAdvancedCustomerAddressList;
import com.igeekhome.pojo.DCustomer;
import com.igeekhome.pojo.DNetwork;
import com.igeekhome.service.ICustomerAddressListService;
import com.igeekhome.service.INetworkService;
import com.igeekhome.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 立以宁
 */
@Controller
@RequestMapping("/page")
public class CustomerController {

@Autowired
private INetworkService networkService;

@Autowired
private CustomerServiceImpl customerService;

@Autowired
private BaseDictControllerApi baseDictControllerApi;

@Autowired
private ICustomerAddressListService customerAddressListService;


@Value("${PAYMENT_METHOD}")
private  String PAYMENT_METHOD;


    /**
     * 查询高级客户列表数据
     */
    @RequestMapping("/customerList")
    public String customerList(){

        return "pages/data/customer/customer";
    }


    /**
     * 查询普通客户列表数据
     */
    @RequestMapping("/ordCustomerList")
    public String ordCustomerList(){

        return "pages/data/customer/ordCustomer";
    }

    @RequestMapping("/addCustomer")
    public String addCustomer(Model model){

        baseDictControllerApi.setCode(PAYMENT_METHOD);
        List<BaseDict> list = baseDictControllerApi.list();
        List<DNetwork> dNetworks = networkService.selectAll();

        model.addAttribute("payMethodList",list);
        model.addAttribute("networkList",dNetworks);
        return "pages/data/customer/addCustomer";
    }

    @RequestMapping("/updateCustomer/{id}")
    public String updateEmployee(@PathVariable("id") Integer id, Model model){
        baseDictControllerApi.setCode(PAYMENT_METHOD);
        List<DNetwork> dNetworks = networkService.selectAll();
        List<BaseDict> list = baseDictControllerApi.list();
        DCustomer dCustomer = customerService.selectById(id);

        model.addAttribute("payMethodList",list);
        model.addAttribute("dCustomer",dCustomer);
        model.addAttribute("networkList",dNetworks);
        return "pages/data/customer/addCustomer";
    }

    /**
     *
     *高级客户地址管理
     *
     */
    @RequestMapping("/addressList/{id}")
    public String addressList(@PathVariable("id") Integer id,Model model){
        model.addAttribute("customerId",id);
        return "pages/data/customer/addressList";
    }

    @RequestMapping("/addAddress/{id}")
    public String addAddress(@PathVariable("id") Integer id,Model model){
        model.addAttribute("userId",id);
        return "pages/data/customer/addAddress";
    }

    @RequestMapping("/updateAddress/{id}")
    public String updateAddress(@PathVariable("id") Integer id,Model model){
        DAdvancedCustomerAddressList dAdvancedCustomerAddressList = customerAddressListService.selectCustomerAddress(id);
        model.addAttribute("company",dAdvancedCustomerAddressList);
        return "pages/data/customer/addAddress";
    }
}
